import re
from typing import Any

from llama_index.core.types import BaseOutputParser


class DeepSeekOutputParse(BaseOutputParser):
    def parse(self, output: str) -> Any:
        """Remove <think> and </think> tags along with their content."""
        # 使用正则表达式匹配<think>...</think>结构，并替换为空字符串
        if output.startswith("<think>"):
            output = re.sub(r'<think>.*?</think>', '', output, flags=re.DOTALL)
        return output
